package com.fengxing.ams.web.security.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.fengxing.ams.pub.AMSException;
import com.fengxing.ams.pub.constants.ReltCode;
import com.fengxing.ams.web.facade.mouble.user.UserVO;
import com.fengxing.ams.web.security.SystemAuthorizingRealm.ShiroUser;

public class PrincipalUtil {
	
	/**
	 * get current user id
	 * 
	 * @return
	 */
	public static final Long getCurrentUserId() {
		Subject currentUser = SecurityUtils.getSubject();
		if (currentUser.isAuthenticated()) {
			ShiroUser user = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			UserVO userVO = user.getUserVO();
			return userVO.getUserId();
		}
		
		throw new AMSException(ReltCode.NO_ACCOUNT);
	}
}
